Public Class frmGLAccountsAdd
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents tbNature As System.Windows.Forms.TextBox
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents tbReport As System.Windows.Forms.TextBox
    Friend WithEvents tbName As System.Windows.Forms.TextBox
    Friend WithEvents tbDpt As System.Windows.Forms.TextBox
    Friend WithEvents cmbAccGroup As DevComponents.DotNetBar.Controls.ComboBoxEx
    Friend WithEvents GroupPanel1 As DevComponents.DotNetBar.Controls.GroupPanel
    Friend WithEvents cmdExit As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdSave As DevComponents.DotNetBar.ButtonX
    Friend WithEvents tbNum As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.tbName = New System.Windows.Forms.TextBox()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.tbNature = New System.Windows.Forms.TextBox()
        Me.tbDpt = New System.Windows.Forms.TextBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.tbNum = New System.Windows.Forms.TextBox()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.tbReport = New System.Windows.Forms.TextBox()
        Me.cmbAccGroup = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        Me.GroupPanel1 = New DevComponents.DotNetBar.Controls.GroupPanel()
        Me.cmdExit = New DevComponents.DotNetBar.ButtonX()
        Me.cmdSave = New DevComponents.DotNetBar.ButtonX()
        Me.GroupPanel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.BackColor = System.Drawing.Color.Transparent
        Me.Label5.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label5.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label5.Location = New System.Drawing.Point(25, 86)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(99, 18)
        Me.Label5.TabIndex = 222
        Me.Label5.Text = "Account Group"
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label1.Location = New System.Drawing.Point(25, 47)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(78, 18)
        Me.Label1.TabIndex = 143
        Me.Label1.Text = "Description"
        '
        'tbName
        '
        Me.tbName.BackColor = System.Drawing.Color.White
        Me.tbName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbName.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.tbName.Location = New System.Drawing.Point(123, 46)
        Me.tbName.MaxLength = 35
        Me.tbName.Name = "tbName"
        Me.tbName.Size = New System.Drawing.Size(298, 26)
        Me.tbName.TabIndex = 140
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.BackColor = System.Drawing.Color.Transparent
        Me.Label4.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label4.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label4.Location = New System.Drawing.Point(25, 121)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(51, 18)
        Me.Label4.TabIndex = 220
        Me.Label4.Text = "Nature"
        '
        'tbNature
        '
        Me.tbNature.BackColor = System.Drawing.Color.White
        Me.tbNature.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbNature.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.tbNature.Location = New System.Drawing.Point(123, 121)
        Me.tbNature.Name = "tbNature"
        Me.tbNature.ReadOnly = True
        Me.tbNature.Size = New System.Drawing.Size(207, 26)
        Me.tbNature.TabIndex = 141
        Me.tbNature.TabStop = False
        '
        'tbDpt
        '
        Me.tbDpt.BackColor = System.Drawing.Color.White
        Me.tbDpt.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbDpt.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.tbDpt.Location = New System.Drawing.Point(218, 9)
        Me.tbDpt.MaxLength = 3
        Me.tbDpt.Name = "tbDpt"
        Me.tbDpt.ReadOnly = True
        Me.tbDpt.Size = New System.Drawing.Size(42, 26)
        Me.tbDpt.TabIndex = 139
        Me.tbDpt.Text = "000"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.BackColor = System.Drawing.Color.Transparent
        Me.Label2.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label2.Location = New System.Drawing.Point(25, 8)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(79, 18)
        Me.Label2.TabIndex = 144
        Me.Label2.Text = "Account No"
        '
        'tbNum
        '
        Me.tbNum.BackColor = System.Drawing.Color.White
        Me.tbNum.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbNum.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.tbNum.Location = New System.Drawing.Point(123, 9)
        Me.tbNum.MaxLength = 4
        Me.tbNum.Name = "tbNum"
        Me.tbNum.Size = New System.Drawing.Size(90, 26)
        Me.tbNum.TabIndex = 138
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.BackColor = System.Drawing.Color.Transparent
        Me.Label6.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label6.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label6.Location = New System.Drawing.Point(25, 156)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(50, 18)
        Me.Label6.TabIndex = 224
        Me.Label6.Text = "Report"
        '
        'tbReport
        '
        Me.tbReport.BackColor = System.Drawing.Color.White
        Me.tbReport.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbReport.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.tbReport.Location = New System.Drawing.Point(123, 156)
        Me.tbReport.Name = "tbReport"
        Me.tbReport.ReadOnly = True
        Me.tbReport.Size = New System.Drawing.Size(207, 26)
        Me.tbReport.TabIndex = 223
        Me.tbReport.TabStop = False
        '
        'cmbAccGroup
        '
        Me.cmbAccGroup.DisplayMember = "Text"
        Me.cmbAccGroup.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbAccGroup.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbAccGroup.ItemHeight = 19
        Me.cmbAccGroup.Location = New System.Drawing.Point(123, 84)
        Me.cmbAccGroup.Name = "cmbAccGroup"
        Me.cmbAccGroup.Size = New System.Drawing.Size(298, 25)
        Me.cmbAccGroup.TabIndex = 225
        '
        'GroupPanel1
        '
        Me.GroupPanel1.CanvasColor = System.Drawing.SystemColors.Control
        Me.GroupPanel1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007
        Me.GroupPanel1.Controls.Add(Me.cmdExit)
        Me.GroupPanel1.Controls.Add(Me.cmdSave)
        Me.GroupPanel1.Controls.Add(Me.cmbAccGroup)
        Me.GroupPanel1.Controls.Add(Me.tbName)
        Me.GroupPanel1.Controls.Add(Me.Label6)
        Me.GroupPanel1.Controls.Add(Me.tbReport)
        Me.GroupPanel1.Controls.Add(Me.Label1)
        Me.GroupPanel1.Controls.Add(Me.tbNum)
        Me.GroupPanel1.Controls.Add(Me.Label2)
        Me.GroupPanel1.Controls.Add(Me.Label4)
        Me.GroupPanel1.Controls.Add(Me.tbDpt)
        Me.GroupPanel1.Controls.Add(Me.tbNature)
        Me.GroupPanel1.Controls.Add(Me.Label5)
        Me.GroupPanel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.GroupPanel1.Location = New System.Drawing.Point(0, 0)
        Me.GroupPanel1.Name = "GroupPanel1"
        Me.GroupPanel1.Size = New System.Drawing.Size(460, 303)
        '
        '
        '
        Me.GroupPanel1.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2
        Me.GroupPanel1.Style.BackColorGradientAngle = 90
        Me.GroupPanel1.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground
        Me.GroupPanel1.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderBottomWidth = 1
        Me.GroupPanel1.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder
        Me.GroupPanel1.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderLeftWidth = 1
        Me.GroupPanel1.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderRightWidth = 1
        Me.GroupPanel1.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderTopWidth = 1
        Me.GroupPanel1.Style.CornerDiameter = 4
        Me.GroupPanel1.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded
        Me.GroupPanel1.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center
        Me.GroupPanel1.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText
        Me.GroupPanel1.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near
        Me.GroupPanel1.TabIndex = 226
        Me.GroupPanel1.Text = " COA - Creation"
        '
        'cmdExit
        '
        Me.cmdExit.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdExit.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdExit.Location = New System.Drawing.Point(339, 220)
        Me.cmdExit.Name = "cmdExit"
        Me.cmdExit.Size = New System.Drawing.Size(82, 27)
        Me.cmdExit.TabIndex = 227
        Me.cmdExit.Text = "Exit"
        '
        'cmdSave
        '
        Me.cmdSave.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdSave.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdSave.Location = New System.Drawing.Point(251, 220)
        Me.cmdSave.Name = "cmdSave"
        Me.cmdSave.Size = New System.Drawing.Size(82, 26)
        Me.cmdSave.TabIndex = 226
        Me.cmdSave.Text = "Save"
        '
        'frmGLAccountsAdd
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(7, 19)
        Me.BackColor = System.Drawing.SystemColors.ActiveCaption
        Me.ClientSize = New System.Drawing.Size(460, 303)
        Me.ControlBox = False
        Me.Controls.Add(Me.GroupPanel1)
        Me.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Location = New System.Drawing.Point(90, 90)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmGLAccountsAdd"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.GroupPanel1.ResumeLayout(False)
        Me.GroupPanel1.PerformLayout()
        Me.ResumeLayout(False)

    End Sub

#End Region
    Private Sub GLaccountsAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadGroupCombos()
    End Sub
    Private Sub LoadGroupCombos()
        Dim GLdata As New GLdataLogic
        Dim ds As DataSet
        ds = GLdata.GetAccountGroups()
        cmbAccGroup.DataSource = ds.Tables(0)
        cmbAccGroup.ValueMember = "GroupID"
        cmbAccGroup.DisplayMember = "GroupName"
        cmbAccGroup.SelectedValue = 0
        GLdata = Nothing
    End Sub

    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        Me.Hide()
    End Sub

    Private Sub cmbAccGroup_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbAccGroup.SelectedIndexChanged
        Try
            Dim rep, nat As String
            Dim GLdata As New GLdataLogic
            Dim ds As DataSet
            ds = GLdata.GetAccountGroupDetails(cmbAccGroup.SelectedValue)
            rep = ds.Tables(0).Rows(0).Item("ReportType")
            nat = ds.Tables(0).Rows(0).Item("AccountType")
            GLdata = Nothing
            If rep = "B" Then
                tbReport.Text = "BALANCE SHEET"
            ElseIf rep = "P" Then
                tbReport.Text = "PROFIT/LOSS STMT"
            End If
            If nat = "AD" Then
                tbNature.Text = "Accumulated Depriciation"
            ElseIf nat = "CH" Then
                tbNature.Text = "Cash / Bank"
            ElseIf nat = "CA" Then
                tbNature.Text = "Current Asset"
            ElseIf nat = "FA" Then
                tbNature.Text = "Fixed Asset"
            ElseIf nat = "CL" Then
                tbNature.Text = "Current Liability"
            ElseIf nat = "PN" Then
                tbNature.Text = "Provisions"
            ElseIf nat = "FL" Then
                tbNature.Text = "Capital / Equity"
            ElseIf nat = "EX" Then
                tbNature.Text = "Expense"
            ElseIf nat = "IN" Then
                tbNature.Text = "Income"
            ElseIf nat = "CS" Then
                tbNature.Text = "Cost"
            ElseIf nat = "SL" Then
                tbNature.Text = "Sale"
            End If
        Catch ex As Exception
            ' MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub tbNum_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbNum.Validated
        If tbNum.Text.Trim <> "" And tbDpt.Text.Trim <> "" Then
            If AccountExist() = True Then
                MsgBox("Account already exist", MsgBoxStyle.Critical, "Inventory Manager")
                tbNum.Text = ""
                tbDpt.Text = ""
                tbNum.Focus()
            End If
        End If
    End Sub

    Private Sub tbDpt_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbDpt.Validated
        If tbNum.Text.Trim <> "" And tbDpt.Text.Trim <> "" Then
            If AccountExist() = True Then
                MsgBox("Account already exist", MsgBoxStyle.Critical, "Inventory Manager")
                tbNum.Text = ""
                tbDpt.Text = ""
                tbNum.Focus()
            End If
        End If
    End Sub
    Private Function AccountExist() As Boolean
        Dim GLdata As New GLdataLogic
        AccountExist = GLdata.AccountExist(CompanyID, tbNum.Text, tbDpt.Text)
        GLdata = Nothing
    End Function

    Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        If tbNum.Text.Trim = "" Or tbDpt.Text.Trim = "" Or tbName.Text.Trim = "" Then
            MsgBox("Input required", MsgBoxStyle.Critical, "Inventory Manager")
            If tbNum.Text.Trim = "" Then
                tbNum.Focus()
                Exit Sub
            End If
            If tbDpt.Text.Trim = "" Then
                tbDpt.Focus()
                Exit Sub
            End If
            If tbName.Text.Trim = "" Then
                tbName.Focus()
                Exit Sub
            End If
        End If
        If cmbAccGroup.SelectedValue = 0 Then
            MsgBox("Account group to be selected", MsgBoxStyle.Critical, "Inventory Manager")
            cmbAccGroup.Focus()
            Exit Sub
        End If
        Dim GLdata As New GLdataLogic
        Dim Response As String
        Response = GLdata.InsertAccountDetails(CompanyID, cmbAccGroup.SelectedValue, tbName.Text, tbNum.Text, tbDpt.Text)
        GLdata = Nothing
        If Response = "OK" Then
            MsgBox("Account created", MsgBoxStyle.Information, "Inventory Manager")
            tbNum.Text = ""
            tbDpt.Text = ""
            tbName.Text = ""
            tbNum.Focus()
        Else
            If Response = "EXIST" Then
                MsgBox("Account already exist !", MsgBoxStyle.Critical, "Inventory Manager")
            Else
                MsgBox("Unable to satisfy your request. Try later", MsgBoxStyle.Critical, "Inventory Manager")
            End If
        End If
    End Sub
End Class
